package com.spiro.normal.bio;

import com.spiro.common.BaseJavaServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;


public class MultiThreadBioServer extends BaseJavaServer {

    private int maxWorkerThread = 8;

    public MultiThreadBioServer(int port) {
        super(port);
    }

    public int getMaxWorkerThread() {
        return maxWorkerThread;
    }

    public void setMaxWorkerThread(int maxWorkerThread) {
        this.maxWorkerThread = maxWorkerThread;
    }

    @Override
    public void serve() {
        try {
            TServerTransport serverTransport = new TServerSocket(this.port);

            TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport)
                    .processor(processor).maxWorkerThreads(this.maxWorkerThread);

            TServer server = new TThreadPoolServer(args);
            System.out.println("Starting the multi-thread bio server...");
            server.serve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
